@extends('layouts.header')
@section('content')
    <div class="prettyprint linenums">
        <form id="myform" class="form form-horizontal">
            <div class="row cl">
                <label class="form-label col-sm-2"><i class="c-red">*</i> 公司名称：</label>
                <div class="formControls col-sm-8">
                    <input class="input-text" type="text" name="company_name" value="{{ $setting_info->name_pass }}">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-sm-2"><i class="c-red">*</i> 工器具名称：</label>
                <div class="formControls col-sm-8">
                    <input class="input-text" type="text" name="tool_name" value="安全帽">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-sm-2">规格型号：</label>
                <div class="formControls col-sm-8">
                    <input class="input-text" type="text" name="guige_xinghao" value="">
                </div>
            </div>

            <div class="row cl">
                <label class="form-label col-sm-2">批次编号：</label>
                <div class="formControls col-sm-8">
                    <input class="input-text" type="text" name="batchNum" value="">
                </div>
            </div>

            <div class="row cl">
                <label class="form-label col-sm-2">试验日期：</label>
                <div class="formControls col-sm-8">
{{--                    <input class="input-text" type="date" name="test_time" value="">--}}
                    <input type="text" name="test_time" value="" onfocus="WdatePicker({dateFmt:'yyyy年MM月dd日'})" class="input-text Wdate">
                </div>
            </div>


            <div class="row cl">
                <label class="form-label col-sm-2">有效日期至：</label>
                <div class="formControls col-sm-8">
                    <input type="text" name="next_time" value="" onfocus="WdatePicker({dateFmt:'yyyy年MM月dd日'})" class="input-text Wdate">
                </div>
            </div>

            <div class="row cl">
                <label class="form-label col-sm-2">试验人员：</label>
                <div class="formControls col-sm-8">
                    <input class="input-text" type="text" name="tester_names" value="">
                </div>
            </div>

            <div class="row cl">
                <label class="form-label col-sm-2">二维码链接：</label>
                <div class="formControls col-sm-8">
                    <input class="input-text" type="text" name="url" value="">
                </div>
            </div>

            <div class="row cl">
                <label class="form-label col-sm-2">打印数量：</label>
                <div class="formControls col-sm-8">
                    <input class="input-text" type="number" name="count" value="1" min="1" max="99">
                </div>
            </div>

            <div class="row cl">
                <label class="form-label col-sm-2"></label>
                <div class="formControls col-sm-8">
                    <a class="btn btn-primary radius" onclick="printPass()">&nbsp;&nbsp;打印&nbsp;&nbsp;</a>
                </div>
            </div>
        </form>
    </div>
    <script type="text/javascript" src="/admin/static/myfolder/js/passedCardContent_{{config('constant.app_name')}}.js?ver={{config('constant.static_res_ver')}}"></script>
    <script>
        var print_depth = "{{ $setting_info->passedcard_print_depth }}";//合格证的打印深度
        var company_name = $('input[name=company_name]').val();//合格证上的公司名称
        var company_name_pos = "{{ $setting_info->passedcard_company_name_pos }}";//合格证的检测公司名称位置
        var is_remote_print = {{ $setting_info->passedcard_is_remote_print }};//合格证为本机打印或远程打印(本机打印:0 , 远程打印:1)
        var ws;
        var wsUrl = 'ws://127.0.0.1:2012';
        $(function () {
            ws_connet();
            $('input[name=batchNum]').val($('td.bar_code:first', window.parent.document).find('span').text().substring(0,6));
        })

        function printPass() {
            let data = [],
                item = {
                    url: $('input[name=url]').val(),
                    res: '合格证',
                    tool_name: $('input[name=tool_name]').val(),
                    guige_xinghao: $('input[name=guige_xinghao]').val(),
                    batchNum: $('input[name=batchNum]').val(),
                    test_time: $('input[name=test_time]').val(),
                    next_time: $('input[name=next_time]').val(),
                    tester_names: $('input[name=tester_names]').val()
                },
                count = $('input[name=count]').val();
            for (let i = 0; i < count; i++) {
                bar_code = parseInt($('input[name=bar_code]').val())+i;
                
                item.bar_code = bar_code
                let data = [item]
                print(data);
                // data.push(item);
            }
        }

        function ws_connet() {
            if (is_remote_print) {
                //远程打印
                wsUrl = 'ws://' + pass_remote_ip + ':2012';
            }
            if ('WebSocket' in window) {
                ws = new WebSocket(wsUrl);
            } else if ('MozWebSocket' in window) {
                ws = new MozWebSocket(wsUrl);
            } else {
                alert('当前浏览器不支持');
            }
            ws.onerror = function () {
                // alert('数据传输发生错误');
                layer.msg('打印服务未开启', {time: 4000});
            }
        }
    </script>
@endsection
